package com.wmeimob.fastboot.jiubei.service;

import com.wmeimob.fastboot.jiubei.entity.ShopGoodsClickRecord;
import com.wmeimob.fastboot.jiubei.mapper.ShopGoodsClickRecordMapper;
import com.wmeimob.fastboot.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @version 1.0
 * @ClassName ShopGoodsClickRecordServiceImpl
 * @Description 商品点击记录表 服务类实现
 * @Author wjt
 * @Date Mon Sep 07 23:58:44 CST 2020
 **/

@Service
@Transactional(rollbackFor = {Exception.class})
@Slf4j
public class ShopGoodsClickRecordServiceImpl implements ShopGoodsClickRecordService {

    @Resource
    private ShopGoodsClickRecordMapper shopGoodsClickRecordMapper;


    @Override
    public List<ShopGoodsClickRecord> list(ShopGoodsClickRecord shopGoodsClickRecord) {
        Example example = new Example(ShopGoodsClickRecord.class);
        Example.Criteria criteria = example.createCriteria();
        if (!StringUtils.isEmpty(shopGoodsClickRecord.getId())) {
            criteria.andEqualTo("id", shopGoodsClickRecord.getId());
        }
        if (!StringUtils.isEmpty(shopGoodsClickRecord.getName())) {
            criteria.andLike("name", StringUtils.fullFuzzy(shopGoodsClickRecord.getName()));
        }
        if (!StringUtils.isEmpty(shopGoodsClickRecord.getUserId())) {
            criteria.andEqualTo("userId", shopGoodsClickRecord.getUserId());
        }
        if (!StringUtils.isEmpty(shopGoodsClickRecord.getOrderId())) {
            criteria.andEqualTo("orderId", shopGoodsClickRecord.getOrderId());
        }
        if (!StringUtils.isEmpty(shopGoodsClickRecord.getGmtCreate())) {
            criteria.andEqualTo("gmtCreate", shopGoodsClickRecord.getGmtCreate());
        }
        example.orderBy("id").desc();
        List<ShopGoodsClickRecord> shopGoodsClickRecords = shopGoodsClickRecordMapper.selectByExample(example);
        return shopGoodsClickRecords;
    }

    @Override
    public ShopGoodsClickRecord queryShopGoodsClickRecordById(Object id) {
        return shopGoodsClickRecordMapper.selectByPrimaryKey(id);
    }


    @Override
    public void addShopGoodsClickRecord(ShopGoodsClickRecord shopGoodsClickRecord) {
        shopGoodsClickRecord.setGmtCreate(new Date());
        shopGoodsClickRecordMapper.insertSelective(shopGoodsClickRecord);
    }

    @Override
    public void removeShopGoodsClickRecord(String id) {
        ShopGoodsClickRecord shopGoodsClickRecord = new ShopGoodsClickRecord();
        shopGoodsClickRecord.setId(id);
        shopGoodsClickRecordMapper.updateByPrimaryKeySelective(shopGoodsClickRecord);
    }

    @Override
    public void modifyShopGoodsClickRecord(ShopGoodsClickRecord shopGoodsClickRecord) {
        shopGoodsClickRecordMapper.updateByPrimaryKeySelective(shopGoodsClickRecord);
    }

}
